package com.star.demo.biz;

import com.star.common.core.contract.Page;
import com.star.common.core.utils.BeanKit;
import com.star.demo.contract.param.DemoParam;
import com.star.demo.contract.query.DemoDetailQuery;
import com.star.demo.contract.query.DemoPageQuery;
import com.star.demo.contract.vo.DemoExportExcelVO;
import com.star.demo.repository.model.DemoBO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用于demo领域的查询相关
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/12/1 17:38
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DemoQueryService {

    /**
     * 通过ID获取demo
     *
     * @param demoDetailQuery id
     * @return demo详情
     */
    public DemoBO getDemoById(DemoDetailQuery demoDetailQuery) {
        return DemoParam.builder().id(demoDetailQuery.getId()).build().one();
    }

    /**
     * 分页查询
     *
     * @param demoPageQuery
     * @return
     */
    public Page<DemoBO> pageDemo(DemoPageQuery demoPageQuery) {
        return BeanKit.copy(demoPageQuery, DemoParam.class).page();
    }

    /**
     * 条件查询
     */
    public void getDemoByCondition() {
        //select * from demo where id=1
        DemoParam.builder().id("1").build().one();


        //单个
        //select * from demo where  name="" and age=10
        DemoParam.builder().name("").age(10).build().one();

        //多个
        //select * from demo where  name="" and age=10
//        DemoParam.builder().name("").age(10).build().list();
    }

    public List<DemoExportExcelVO> downloadDemo(DemoPageQuery demoPageQuery) {
        List<DemoBO> list = BeanKit.copy(demoPageQuery, DemoParam.class).list();
        return list.stream()
                .map(data -> BeanKit.copy(data, DemoExportExcelVO.class)).toList();
    }
}
